package controllers

import (
	"encoding/json"
	"weiboxs.com/new_h_glasses/models"
)

type AcceptanceController struct {
	BaseController
}

func (c *AcceptanceController) Prepare() {
	c.BaseController.Prepare()

	c.Data["activeSidebarUrl"] = "/acceptance/index"
}

func (c *AcceptanceController) Index() {
	c.checkAuthor("acceptance/index")

	if c.Ctx.Input.IsPost() {
		var qs models.ErpAcceptanceQueryParam
		json.Unmarshal(c.Ctx.Input.RequestBody, &qs)
		qs.DepartmentId = c.curUser.DepartmentId
		data, count := models.ErpAcceptancePageList(&qs)
		c.jsonDataTable(count, data)
	}

	c.display("", "acceptance/index_footerjs.html")
}

func (c *AcceptanceController) Details() {
	c.checkAuthor("acceptance/index")
	id,_:= c.GetInt64(":id")
	if id == 0 {
		c.pageError("参数不正确")
	}
	if c.Ctx.Input.IsPost() {
		var qs models.ErpAcceptanceDataQueryParam
		json.Unmarshal(c.Ctx.Input.RequestBody, &qs)
		qs.Acceptance = id
		qs.RelatedSel = []interface{}{"Products", "Snd"}
		data, count := models.ErpAcceptanceDataPageList(&qs)
		c.jsonDataTable(count, data)
	}
	c.display("", "acceptance/details_footerjs.html", "shared/layout_dialog.html")
}